import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options

# 打开浏览器
service = Service(r'D:\Python3.14\chromedriver.exe')
chrome_options = Options()
chrome_options.add_experimental_option("detach", True)
driver = webdriver.Chrome(service=service, options=chrome_options)   # 创建浏览器对象
# 输入访问网址
driver.get("https://www.baidu.com")
driver.maximize_window()

"""
需求：使用cookie实现跳过登录
1). 手动登录百度，获取cookie
2). 使用获取到的cookie，达到登录目的，然后就可以执行登录之后的操作
"""
driver.add_cookie({'name': 'BDUSS', "value": "ZtenRUU1VkdXBPU01JbDZ-dzRyc3JtTUhqdTVJQ25tZy1mTXlaWWNjUU8taXRwSUFBQUFBJCQAAAAAAAAAAAEAAAAEzSo3AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA5tBGkObQRpbm"})
time.sleep(3)
driver.refresh()
time.sleep(3)
driver.quit()

